<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 后台菜单管理
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class Upload extends Admin_Controller{
	
	function __construct(){
		parent::__construct();
		$this->load->model('JayphaDB');
		$this->load->model('JayphaTemplate');
		$this->load->helper('form');
		$this->adminCurrentTemplate = $this->JayphaDB->getConfigValue('adminCurrentTemplate');
		if(is_null($this->adminCurrentTemplate) or empty($this->adminCurrentTemplate)){
			$this->adminCurrentTemplate = 'default';
		}
		$this->dbTablePrefix = $this->config->item('db_table_prefix');
	}
	
	function index(){
		parse_str($this->input->server('QUERY_STRING'),$this->input->get());		
		if(!$this->noLoginErr()) return false;
		$data['adminCurrentTemplate'] = $this->adminCurrentTemplate;
		$data['perm'] = 'upload';
		$data['type'] = $this->input->get_post('type');
		$data['returnInput'] = $this->input->get_post('returnInput');
		$tvName = 'upload';		
		if($this->input->server('REQUEST_METHOD')=='POST'){
			switch(strtolower($data['type'])){
				case 'img':
					$config['upload_path'] = './uploadFiles/images/';
					$config['allowed_types'] = 'gif|jpg|png|jpeg';
					break;
				case 'media':
					$config['upload_path'] = './uploadFiles/flash/';
					$config['allowed_types'] = 'flv|swf|mp4|avi|wmv|3g';
					break;
				default:
					$config['upload_path'] = './uploadFiles/files/';
					$config['allowed_types'] = 'doc|docx|ppt|rar|zip|txt';
					break;
			}
			$data['upload_path'] = $config['upload_path'];
			$config['max_size'] = '100';
			$config['encrypt_name'] = true;
			$config['remove_spaces'] = true;
			$this->load->library('upload', $config);
			$field_name = 'file';
			if(!$this->upload->do_upload($field_name)){
				$data['error'] = $this->upload->display_errors();
			}else{
				$data['upfile'] = $this->upload->data();
			}
		}
		$this->load->view("admin/$this->adminCurrentTemplate/upload",$data);
	}
}

/* End of file upload.php */
/* Location: ./application/controllers/admin/upload.php */